package com.example.demo3.others;


import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Controller
//@RestController
@RequestMapping("/response")
public class Response {
    @RequestMapping("/returnHtml")
    public String v1(){
        return "/hello.html";
    }

    @RequestMapping("/returnJson")
    @ResponseBody
    public HashMap<String,String> v2(){
        HashMap<String,String> map = new HashMap<>();
        map.put("java","1");
        map.put("python","22");
        map.put("c++","333");
        return map;
    }

    @RequestMapping("/returnStatus")
    @ResponseBody
    public String v3(HttpServletResponse response){
        User user = new User();
        user.setName("zhangsan");
        user.setAge(18);
        user.setGender("女");
        response.setStatus(666);
        return ""+user;
    }

    @RequestMapping(value = "/setHeader1", produces = "application/json;charset = utf-8")
    @ResponseBody
    public String v4(){
        return "header设置成功"+"{\"success\": ture}";
    }

    @RequestMapping("/setHeader2")
    @ResponseBody
    public String v5(HttpServletResponse response){
        response.setHeader("My","MyValue");
        return "header设置成功";
    }
}
